<?php
namespace Home\Controller;
use Think\Controller;
class PlayerController extends BaseController{

   //获取用户的openid
    public function getBaseInfo(){
        $appid='wx3c484176a1ad105d';
        $redirect_uri=urlencode('http://dwc.gametu.com/think/index.php?g=Home&m=player&a=getUserOpenid');
        $url='https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$appid.'&redirect_uri='.$redirect_uri.'&response_type=code&scope=snsapi_base&state=123#wechat_redirect';
        //var_dump($url);
        header("location:".$url);
    }

    public function getUserOpenid(){
        $appid = 'wx3c484176a1ad105d';
        $appsecret = 'b314e4774f61a3ac2d81a82e8d71d93f';
        $code=$_GET['code'];
        $url='https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$appid.'&secret='.$appsecret.'&code='.$code.'&grant_type=authorization_code';
        $res = $this->http_curl($url, 'get', 'json');
        $this->display();
    }
    //新手礼包
    public function gift(){
        //$user_info=$this->getBaseInfo();
        //$openid=$user_info['openid'];

        $this->display();
    }
    
    //安全中心
    public function anquan(){
        $this->display();
    }
    //充值
    public function pay(){
        $this->display();
    }


    public function http_curl($url, $type = 'get', $res = 'json', $arr = '')
    {
        //1.初始化，创建一个新cURL资源
        $ch = curl_init();
        //2.设置URL和相应的选项
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//  不验证证书
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);//  不验证证书
        if ($type == 'post') {
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $arr);
        }
        //3.抓取URL并把它传递给浏览器
        $output = curl_exec($ch);
        if ($res == 'json') {
            return json_decode($output, true);
        }
        //4.关闭cURL资源，并且释放系统资源
        curl_close($ch);
    }
}